package com.mutouren.modules.datapush.client;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.mutouren.modules.datapush.LocalManager;
import com.mutouren.modules.datapush.base.Constant;
import com.mutouren.modules.datapush.base.PushClient;
import com.mutouren.modules.datapush.local.KafkaServerProxy;

/**
 * Demo: 推送中心模式，需要启动 mtr-datapush-server 服务 kafka
 * 
 */
public class PushClientTest_Remote_kafka {
	private final static String serverAlias = "pushserver-proxy1";
	//private final static String serverUrl = "http://192.168.1.105:8080/mtr-datapush-server-web/api/send";
	private final static String bootstrapServers = "192.168.1.105:9092";
	
	@BeforeClass
	public static void before() {
		System.out.println("event: before");				
		LocalManager.register(new KafkaServerProxy(serverAlias, bootstrapServers));		
		LocalManager.open("e:/logs-data/push-data", false);
	}
	
	@AfterClass
	public static void after() {
		LocalManager.close();
		System.out.println("event: after");		
	}

	@Test
	public void test() throws InterruptedException {
		String url = "http://localhost:8080/mtr-web-demo/api/demo/hello?helloword=ok";
		//String url = "http://localhost:8080/mtr-web-demo/api/demo/delay?delaytime=10000";
		
		PushClient dpClient = new SimplePushClient(url, Constant.defaultMethodAlias, serverAlias);
		
		for(int i = 0; i < 10; i ++ ) {
			String dataPackage = "Hello, I am kafka server: " + i; 
			dpClient.send(dataPackage);
		}	

		Thread.sleep(10000);
		
		System.out.println("event: test() is end");	
	}
}